﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lost_and_Found.Models.DB;
using Lost_and_Found.Models.ObjectManager;
using Lost_and_Found.Models.ViewModel;

namespace Lost_and_Found.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        TopicManager tpManager = new TopicManager();
        LAFEntities db = new LAFEntities();

        public ActionResult Index()
        {
            return View();
        }
		[HttpPost]
        public JsonResult getTopicPage(string type,int id, int size)
        {
            var x = tpManager.getTopicPage(type,id, size);
            return Json(x);
        }

       
        public ActionResult ShowTopic(int ID)
        {
            ViewBag.nameAccess2 = db.Topics.Find(ID).User.Username;

            var topic = tpManager.getTopic(ID);
            if (topic == null)
            {
                return HttpNotFound();
            }
            TopicInfo tpInfo = new TopicInfo(topic);
            return View(tpInfo);
        }

		
		
        public ActionResult Test()
        {
            return View();
        }

        [HttpPost]
        public ActionResult OutData(int name)
        {
            List<int> list = new List<int>();
            for (int i = 0; i < name; i++)
                list.Add(i);

            return Json(list);
        }
      
        public ActionResult Search(int topicToSearch) 
        {

            if (User.Identity.Name.Equals(db.Topics.Find(topicToSearch).User.Username))
            {
                ViewBag.ABC = topicToSearch + "";
                return View();
            }
            else return Redirect("~");
        }
        
        [HttpPost]
        public JsonResult Search(int topicToSearch,int pageId, int pageSize)
        {
            TopicPage page = tpManager.getTopicHasTheItem(topicToSearch,pageId, pageSize);
            return Json(page);
        }

        

    }
}
